package cn.xz.hfsk.util

import android.content.Intent
import cn.xz.hfsk.base.BaseApplication
import cn.xz.hfsk.bean.CommonLib

/**
 * 界面跳转
 * */
object ARouter {

    //基础跳转
    fun to(cls: Class<*>?){
        val intent = Intent(BaseApplication.getContext(), cls)
        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        BaseApplication.getContext().startActivity(intent)
    }

    //跳转携参
    fun to(cls: Class<*>?,d: Int){
        val intent = Intent(BaseApplication.getContext(), cls)
        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        intent.putExtra(CommonLib.JUMP_TYPE,d)
        BaseApplication.getContext().startActivity(intent)
    }

    fun to(cls: Class<*>?,d: String){
        val intent = Intent(BaseApplication.getContext(), cls)
        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        intent.putExtra(CommonLib.JUMP_TYPE,d)
        BaseApplication.getContext().startActivity(intent)
    }

    //跳到指定界面，并且销毁其他界面
    fun dto(c: Class<*>){
        val intent = Intent(BaseApplication.getContext(), c)
        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        BaseApplication.getContext().startActivity(intent)
        val mList = BaseApplication.getActivityList()
        if (mList != null && mList.isNotEmpty()){
            mList.forEach {
                if (!c.name.contains(it.localClassName)){
                    it.finish()
                }
            }
        }
    }

}